package cn.lg.soar.boot.client.api.token;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * API接口令牌通用配置
 * 
 * @author helios
 */
@Configuration
public class ClientTokenConfig implements WebMvcConfigurer
{
    @Autowired ClientTokenInterceptor fondleTokenInterceptor;
    
    /**
     * API接口令牌拦截规则
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor((HandlerInterceptor) fondleTokenInterceptor).addPathPatterns("/api/**");
    }
    
    /**
     * 跨域支持配置
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowCredentials(true).allowedOriginPatterns("*").allowedMethods("GET", "PUT", "DELETE", "POST", "OPTIONS").maxAge(3600);
    }
}